﻿//© Copyright DevHost Ltd, 2005. All Rights Reserved. http://www.Fast-Help.com
var include_num = 1;
var bold = 0;
var boFTS = 0;
var s = new Array();
s[0] = "Index^Index.html^Bienvenido a la Ayuda de Sistema para EmpleosAquí podrá encontrar como Ingresar, Eliminar y Desp...^^`;";
s[1] = "Ingresar Empresa^IngresarDato.html^Para ingresar una nueva empresa, presione el botón `Ingresar Empresa` que se encuentra en la página ...^Ingresar Empresa^`;";
s[2] = "Eliminar Empresa^EliminarEmpresa.html^Para eliminar una empresa, debe presionar el botón `Eliminar Empresa` en la página principal. Esto l...^Eliminar Empresa^`;";
s[3] = "Conectar con Base de Datos^ConectarConBaseDeDatos.html^El botón Iniciar Base de Datos, permite hacer una búsqueda inicial en la base de datos para desplega...^Conectar con Base de Datos^`;";

var stCookies = document.cookie;
var p = stCookies.indexOf("d=");
if (p != -1)
{
  var st = p + 2;
  var en = stCookies.indexOf(";", st);
  if (en == -1)
    {en = stCookies.length;}
  var d = stCookies.substring(st, en);
  d = unescape(d);
}

var iUsingDoubleQuotes = 0;
if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"')
  {iUsingDoubleQuotes = 1;}

var arFound = new Array();
var iFound = 0;
var iRankNumber = 0;
if (iUsingDoubleQuotes == 0)
{
  var arMinus = new Array();
  var arIncludedTerms = new Array();
  var w = d.split(" ");
  for (var a = 0; a < w.length; a++)
  {
    arMinus[a] = 0;
    if (w[a].charAt(0) == '-')
      {arMinus[a] = 1;}
    else
      {arIncludedTerms.push(w[a]);}
  }

  for (var a = 0; a < w.length; a++)
    {w[a] = w[a].replace(/^\-|^\+/gi, "");}

  a = 0;
  for (var c = 0; c < s.length; c++)
  {
    pa = 0;
    nh = 0;
    for (var i = 0; i < arMinus.length; i++)
    {
      if (arMinus[i] == 0)
      {
        nh++;
        var pat = new RegExp(w[i], "i");
        var rn = s[c].search(pat);
        if (rn >= 0)
          {pa++;}
        else
          {pa = 0;}
      }

      if (arMinus[i] == 1)
      {
        var pat = new RegExp(w[i], "i");
        var rn = s[c].search(pat);
        if (rn >= 0)
          {pa = 0;}
      }
    }

    if (pa == nh)
    {
      var es = s[c].split('^');
      var iRank = 100;
      var iTermsFound = 0;
      var iTitlePercentage = 15;
      var iKeywordsPercentage = 25;
      var iHelpTextPercentage = 60;
      for (var ii = 0; ii < arIncludedTerms.length; ii++)
      {
        var patTerm = new RegExp(arIncludedTerms[ii], "i");
        var iPT = es[0].search(patTerm);
        if (iPT >= 0)
          {iTermsFound++;}
      }
      if (iTermsFound < arIncludedTerms.length)
        {iTitlePercentage = Math.round(iTitlePercentage * (iTermsFound/arIncludedTerms.length));}
      if (iTitlePercentage < 0)
        {iTitlePercentage = 0;}
      iTermsFound = 0;
      for (var ii = 0; ii < arIncludedTerms.length; ii++)
      {
        var patTerm = new RegExp(arIncludedTerms[ii], "i");
        var iPT = es[3].search(patTerm);
        if (iPT >= 0)
          {iTermsFound++;}
      }
      if (iTermsFound < arIncludedTerms.length)
        {iKeywordsPercentage = Math.round(iKeywordsPercentage * (iTermsFound/arIncludedTerms.length));}
      if (iKeywordsPercentage <= 0)
        {iKeywordsPercentage = 1;}
      iTermsFound = 0;
      for (var ii = 0; ii < arIncludedTerms.length; ii++)
      {
        var patTerm = new RegExp(arIncludedTerms[ii], "i");
        if (boFTS == 0)
          {var iPT = es[2].search(patTerm);}
        else
          {var iPT = es[4].search(patTerm);}

        if (iPT >= 0)
          {iTermsFound++;}
      }
      if (iTermsFound < arIncludedTerms.length)
        {iHelpTextPercentage = Math.round(iHelpTextPercentage * (iTermsFound/arIncludedTerms.length));}
      if (iHelpTextPercentage < 0)
        {iHelpTextPercentage = 0;}
      iRank = iTitlePercentage + iKeywordsPercentage + iHelpTextPercentage;
      arFound[a] = iRank + '^' + s[c];
      a++;
    }
  }
  iFound = a;
  arFound.sort(compareNum);
  arFound.reverse();
}

if (iUsingDoubleQuotes == 1)
{
  d = d.replace(/"/gi, "");
  var arMinus = new Array();
  var arIncludedTerms = new Array();
  var w = d.split(" ");
  for (var a = 0; a < w.length; a++)
  {
    arMinus[a] = 0;
    if (w[a].charAt(0) == '-')
      {arMinus[a] = 1;}
    else
      {arIncludedTerms.push(w[a]);}
  }
  var a = 0;
  var pat = new RegExp(d, "i");
  for (var c = 0; c < s.length; c++)
  {
    var rn = s[c].search(pat);
    if (rn >= 0)
    {
      var es = s[c].split('^');
      var iRank = 100;
      var iTermsFound = 0;
      var iTitlePercentage = 15;
      var iKeywordsPercentage = 25;
      var iHelpTextPercentage = 60;
      for (var ii = 0; ii < arIncludedTerms.length; ii++)
      {
        var patTerm = new RegExp(arIncludedTerms[ii], "i");
        var iPT = es[0].search(patTerm);
        if (iPT >= 0)
          {iTermsFound++;}
      }
      if (iTermsFound < arIncludedTerms.length)
        {iTitlePercentage = Math.round(iTitlePercentage * (iTermsFound/arIncludedTerms.length));}
      if (iTitlePercentage < 0)
        {iTitlePercentage = 0;}
      iTermsFound = 0;
      for (var ii = 0; ii < arIncludedTerms.length; ii++)
      {
        var patTerm = new RegExp(arIncludedTerms[ii], "i");
        var iPT = es[3].search(patTerm);
        if (iPT >= 0)
          {iTermsFound++;}
      }
      if (iTermsFound < arIncludedTerms.length)
        {iKeywordsPercentage = Math.round(iKeywordsPercentage * (iTermsFound/arIncludedTerms.length));}
      if (iKeywordsPercentage <= 0)
        {iKeywordsPercentage = 1;}
      iTermsFound = 0;
      for (var ii = 0; ii < arIncludedTerms.length; ii++)
      {
        var patTerm = new RegExp(arIncludedTerms[ii], "i");
        if (boFTS == 0)
          {var iPT = es[2].search(patTerm);}
        else
          {var iPT = es[4].search(patTerm);}
        if (iPT >= 0)
          {iTermsFound++;}
      }
      if (iTermsFound < arIncludedTerms.length)
        {iHelpTextPercentage = Math.round(iHelpTextPercentage * (iTermsFound/arIncludedTerms.length));}
      if (iHelpTextPercentage < 0)
        {iHelpTextPercentage = 0;}
      iRank = iTitlePercentage + iKeywordsPercentage + iHelpTextPercentage;
      arFound[a] = iRank + '^' + s[c];
      a++;
    }
  }
  iFound = a;
  arFound.sort(compareNum);
  arFound.reverse();
}

function return_query()
{
  document.jse_Form.d.value = d;
}

function compareNum(a,b)
{
  var arA = a.split("^");
  var arB = b.split("^");
  return arA[0]-arB[0]
}

function num_jse()
{
  document.write(iFound);
}

function out_jse()
{
  if (iFound == 0)
  {
    document.write('Your search did not match any documents.<br>Please ensure that all keywords are spelled correctly.<br>Or try different or more general keywords. Thank you.');
    return;
  }
  for (var a = 0; a < arFound.length; a++)
  {
    var os = arFound[a].split("^");
    if (bold == 1 && iUsingDoubleQuotes == 1)
    {
      var br = "<b>" + d + "</b>";
      os[3] = os[3].replace(pat, br);
    }
    var stRank = '';
    if (include_num == 1)
      {document.write(a + 1, '. <a href="', os[2], '">', os[1], '</a>', stRank, '<br>', os[3], '<p>');}
    else
      {document.write('<a href="', os[2], '">', os[1], '</a>', stRank, '<br>', os[3], '<p>');}
  }
}